////////////////////////////////////////////////////////////////////////////////
///////// Product Market Competition and Convertible Debt Financing ////////////
///////// Cheng Lei, Evgeny Lyandres, Chris Veld, Ying Xia /////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
* Date: April 27, 2024
* This do file contains code generating results for Tables 6 to 8
* Please define the path for datasets and the path for storing results before running the following program. 
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
* Use the firm-year sample with additional variables
* [Baseline_Firm_Year_Sample]

use "Path\Baseline_Firm_Year_Sample.dta", clear

* Control variable
global control size lage cash i.divd i.rep cf tangib capex mb rda Vol_12 

********************************************************************************
* Table 6 The Role of Relative Financial Strength
********************************************************************************
* Full firm-year sample with available data
* Panel A - Table 6
* Model 1
probit convo c.fld##i.rankdcd1 $control i.icode50 i.fyear  , vce(cluster gvkey)
estimates store a1

* Model 2
probit covdum c.fld##i.rankdcd1 $control i.icode50 i.fyear , vce(cluster gvkey)
estimates store a2

* Model 3
tobit fconv1 c.fld##i.rankdcd1 $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a3

* Model 4
tobit fconv2 c.fld##i.rankdcd1 $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a4

*Panel B - Table 6
* Model 1
probit convo c.fld##i.rankdkz $control i.icode50 i.fyear  , vce(cluster gvkey)
estimates store a5

* Model 2
probit covdum c.fld##i.rankdkz $control i.icode50 i.fyear , vce(cluster gvkey)
estimates store a6

* Model 3
tobit fconv1 c.fld##i.rankdkz $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a7

* Model 4
tobit fconv2 c.fld##i.rankdkz $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a8


esttab  a1 a2 a3 a4 a5 a6 a7 a8 using "Path\Table_6.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps

********************************************************************************


********************************************************************************
* Table 7 The Role of Excess Leverage and Access to Public Debt Markets
********************************************************************************
* Panel A - Table 7 
* Full firm-year sample with available data

* Model 1
probit convo c.fld##i.hrnl $control i.icode50 i.fyear  , vce(cluster gvkey)
estimates store a1

* Model 2
probit covdum c.fld##i.hrnl $control i.icode50 i.fyear , vce(cluster gvkey)
estimates store a2

* Model 3
tobit fconv1 c.fld##i.hrnl $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a3

* Model 4
tobit fconv2 c.fld##i.hrnl $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a4


* Panel B - Table 7 
* Subsample of unrated firms
global condition if unrate == 1 

* Model 1
probit convo c.fld##i.hrnl $control i.icode50 i.fyear $condition, vce(cluster gvkey)
estimates store a5

* Model 2
probit covdum c.fld##i.hrnl $control i.icode50 i.fyear $condition, vce(cluster gvkey)
estimates store a6

* Model 3
tobit fconv1 c.fld##i.hrnl $control i.icode50 i.fyear $condition, ll(0) vce(cluster gvkey)
estimates store a7

* Model 4
tobit fconv2 c.fld##i.hrnl $control i.icode50 i.fyear $condition, ll(0) vce(cluster gvkey)
estimates store a8

* Panel C - Table 7 
* Subsample of rated firms
global condition if unrate == 0 

* Model 1
probit convo c.fld##i.hrnl $control i.icode50 i.fyear $condition, vce(cluster gvkey)
estimates store a9

* Model 2
probit covdum c.fld##i.hrnl $control i.icode50 i.fyear $condition, vce(cluster gvkey)
estimates store a10

* Model 3
tobit fconv1 c.fld##i.hrnl $control i.icode50 i.fyear $condition, ll(0) vce(cluster gvkey)
estimates store a11

* Model 4
tobit fconv2 c.fld##i.hrnl $control i.icode50 i.fyear $condition, ll(0) vce(cluster gvkey)
estimates store a12


esttab  a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12  using "Path\Table_7.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps

********************************************************************************

********************************************************************************
* Table 8 The Role of Competitive Positions
********************************************************************************
* Full firm-year sample with available data
* Model 1
probit convo c.fld##i.rankrncites1 $control i.icode50 i.fyear , vce(cluster gvkey)
estimates store a1

* Model 2
probit covdum c.fld##i.rankrncites1 $control i.icode50 i.fyear , vce(cluster gvkey)
estimates store a2

* Model 3
tobit fconv1 c.fld##i.rankrncites1 $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a3

* Model 4
tobit fconv2 c.fld##i.rankrncites1 $control i.icode50 i.fyear , ll(0) vce(cluster gvkey)
estimates store a4



esttab  a1 a2 a3 a4  using "Path\Table_8.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps

********************************************************************************

////////////////////////////////////////////////////////////////////////////////
* The above codes generate the result, and the format of table is finalised in Excel. 
* For Probit and Tobit regressions, vce(cluster gvkey) is equivalent to Cluster(gvkey)
////////////////////////////////////////////////////////////////////////////////

